<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-imu.h</h1>  </div>
</div>
<div class="contents">
<a href="mindsensors-imu_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup mindsensors</span>
<a name="l00002"></a>00002 <span class="comment"> * @{</span>
<a name="l00003"></a>00003 <span class="comment"> * @defgroup MSIMU AbsoluteIMU Sensor</span>
<a name="l00004"></a>00004 <span class="comment"> * Mindsensors AbsoluteIMU Sensor (MSIMU) driver</span>
<a name="l00005"></a>00005 <span class="comment"> * @{</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">/*</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: mindsensors-imu.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef __MSIMU_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define __MSIMU_H__</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment">/** \file mindsensors-imu.h</span>
<a name="l00015"></a>00015 <span class="comment"> * \brief Mindsensors AbsoluteIMU Sensor driver</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * mindsensors-imu.h provides an API for the Mindsensors AbsoluteIMU Sensor.</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> * Changelog:</span>
<a name="l00020"></a>00020 <span class="comment"> * - 0.1: Initial release</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * Credits:</span>
<a name="l00023"></a>00023 <span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00028"></a>00028 <span class="comment"></span>
<a name="l00029"></a>00029 <span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<a name="l00030"></a>00030 <span class="comment"> * \date 23 August 2012</span>
<a name="l00031"></a>00031 <span class="comment"> * \version 0.1</span>
<a name="l00032"></a>00032 <span class="comment"> * \example mindsensors-imu-test1.c</span>
<a name="l00033"></a>00033 <span class="comment"> * \example mindsensors-imu-test2.c</span>
<a name="l00034"></a>00034 <span class="comment"> * \example mindsensors-imu-test3.c</span>
<a name="l00035"></a>00035 <span class="comment"> */</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#pragma systemFile</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#endif</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a><a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">00043</a> <span class="preprocessor">#define MSIMU_IMU_I2C_ADDR            0x22  </span><span class="comment">/*!&lt; IMU I2C address */</span>
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="group___m_s_i_m_u.html#gaf0b1aebfb7bcbece8a48e41e22d381d4">00045</a> <span class="preprocessor">#define MSIMU_REG_CMD                 0x41  </span><span class="comment">/*!&lt; Command register */</span>
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="group___m_s_i_m_u.html#gad51c9b76f348df2462e82013ac22cb98">00047</a> <span class="preprocessor">#define MSIMU_REG_TILT_ALL_AXES       0x42  </span><span class="comment">/*!&lt; All Axes for Tilt */</span>
<a name="l00048"></a><a class="code" href="group___m_s_i_m_u.html#ga15de9f02904e24957dea410855d5b5e4">00048</a> <span class="preprocessor">#define MSIMU_REG_ACC_ALL_AXES        0x45  </span><span class="comment">/*!&lt; All Axes for Accel */</span>
<a name="l00049"></a><a class="code" href="group___m_s_i_m_u.html#gaa9876d9b5b9d3b7dfd15bc520fab614e">00049</a> <span class="preprocessor">#define MSIMU_REG_COMPASS_HEADING     0x4B  </span><span class="comment">/*!&lt; Compass heading */</span>
<a name="l00050"></a><a class="code" href="group___m_s_i_m_u.html#ga5c8fb09b4f85fb73e192fd84c56bbcc5">00050</a> <span class="preprocessor">#define MSIMU_REG_COMPASS_ALL_FIELDS  0x4D  </span><span class="comment">/*!&lt; All magnetic fields for compass */</span>
<a name="l00051"></a><a class="code" href="group___m_s_i_m_u.html#gae32355c9166051c7fd3a544c1718ada2">00051</a> <span class="preprocessor">#define MSIMU_REG_GYRO_ALL_AXES       0x53  </span><span class="comment">/*!&lt; All Axes for Gyro */</span>
<a name="l00052"></a><a class="code" href="group___m_s_i_m_u.html#ga4dd0432a1d355b19202419cd4fcf4d84">00052</a> <span class="preprocessor">#define MSIMU_REG_GYRO_FILTER         0x5A  </span><span class="comment">/*!&lt; Filter level for Gyro */</span>
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="group___m_s_i_m_u.html#ga03707ad1b87c0699dcd147b513f049a7">00054</a> <span class="preprocessor">#define MSIMU_CMD_COMPASS_START_CAL   0x43  </span><span class="comment">/*!&lt; Accelerometer 2G range */</span>
<a name="l00055"></a><a class="code" href="group___m_s_i_m_u.html#gab97fdb2bc29124f6b50934899cea60d6">00055</a> <span class="preprocessor">#define MSIMU_CMD_COMPASS_STOP_CAL    0x63  </span><span class="comment">/*!&lt; Accelerometer 2G range */</span>
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="group___m_s_i_m_u.html#gab3d39ed6945825ae545b87fd2e96597a">00057</a> <span class="preprocessor">#define MSIMU_CMD_ACC_RANGE_2G        0x31  </span><span class="comment">/*!&lt; Accelerometer 2G range */</span>
<a name="l00058"></a><a class="code" href="group___m_s_i_m_u.html#ga1db8e9184ae78cef3d5e565c59361da5">00058</a> <span class="preprocessor">#define MSIMU_CMD_ACC_RANGE_4G        0x32  </span><span class="comment">/*!&lt; Accelerometer 4G range */</span>
<a name="l00059"></a><a class="code" href="group___m_s_i_m_u.html#gad4329324a23af016799f0b000ec01871">00059</a> <span class="preprocessor">#define MSIMU_CMD_ACC_RANGE_8G        0x33  </span><span class="comment">/*!&lt; Accelerometer 8G range */</span>
<a name="l00060"></a><a class="code" href="group___m_s_i_m_u.html#ga1e58091391f56ea0515edb0b571d67a2">00060</a> <span class="preprocessor">#define MSIMU_CMD_ACC_RANGE_16G       0x34  </span><span class="comment">/*!&lt; Accelerometer 16G range */</span>
<a name="l00061"></a>00061 
<a name="l00062"></a><a class="code" href="group___m_s_i_m_u.html#gaad4e02250e95a5c4a00c9b85b5d7e6de">00062</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_NONE        0     </span><span class="comment">/*!&lt; Gyro filter level: none */</span>
<a name="l00063"></a><a class="code" href="group___m_s_i_m_u.html#gae717964be01f52e604d04a8174a3c0f2">00063</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_1     1     </span><span class="comment">/*!&lt; Gyro filter level: 1 */</span>
<a name="l00064"></a><a class="code" href="group___m_s_i_m_u.html#gac4efe3bd68c952f77879d7c65aab2822">00064</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_2     2     </span><span class="comment">/*!&lt; Gyro filter level: 2 */</span>
<a name="l00065"></a><a class="code" href="group___m_s_i_m_u.html#gacdf968da85c234429f33952f641a09fe">00065</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_3     3     </span><span class="comment">/*!&lt; Gyro filter level: 3 */</span>
<a name="l00066"></a><a class="code" href="group___m_s_i_m_u.html#gaa584c6fef1c88757433e48cbe8ab9b98">00066</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_4     4     </span><span class="comment">/*!&lt; Gyro filter level: 4 (default) */</span>
<a name="l00067"></a><a class="code" href="group___m_s_i_m_u.html#ga3bb543a8e7610eb89f40b2582519fccc">00067</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_5     5     </span><span class="comment">/*!&lt; Gyro filter level: 5 */</span>
<a name="l00068"></a><a class="code" href="group___m_s_i_m_u.html#gab6f4423d9dc7a519800fe875f3501524">00068</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_6     6     </span><span class="comment">/*!&lt; Gyro filter level: 6 */</span>
<a name="l00069"></a><a class="code" href="group___m_s_i_m_u.html#ga9189a10c20c1d68d511645ad933653a7">00069</a> <span class="preprocessor">#define MSIMU_GYRO_FILTER_LEVEL_7     7     </span><span class="comment">/*!&lt; Gyro filter level: 7 (highest) */</span>
<a name="l00070"></a>00070 
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="group___m_s_i_m_u.html#gaf1b80334857e08e7577840d80f442ebe">00072</a> <span class="preprocessor">#define MSIMU_TILT_X_AXIS           MSIMU_REG_TILT_X_AXIS</span>
<a name="l00073"></a><a class="code" href="group___m_s_i_m_u.html#ga90c69d6d0c15458904534580dbea83a2">00073</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_TILT_Y_AXIS           MSIMU_REG_TILT_Y_AXIS</span>
<a name="l00074"></a><a class="code" href="group___m_s_i_m_u.html#gacdac62e500702d32541e273251ef57bc">00074</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_TILT_Z_AXIS           MSIMU_REG_TILT_Z_AXIS</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span>
<a name="l00076"></a><a class="code" href="group___m_s_i_m_u.html#ga5ff47a32e57466e62f92f2fea44465b7">00076</a> <span class="preprocessor">#define MSIMU_ACC_X_AXIS            MSIMU_REG_ACC_X_AXIS</span>
<a name="l00077"></a><a class="code" href="group___m_s_i_m_u.html#ga5822f1c91b7db7aed055972b79e942f2">00077</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_ACC_Y_AXIS            MSIMU_REG_ACC_Y_AXIS</span>
<a name="l00078"></a><a class="code" href="group___m_s_i_m_u.html#ga938a63a8a640ef9f6a7f40dd6fac006f">00078</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_ACC_Z_AXIS            MSIMU_REG_ACC_Z_AXIS</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span>
<a name="l00080"></a><a class="code" href="group___m_s_i_m_u.html#ga46f1427746efe302ba98c3fb3d4603e2">00080</a> <span class="preprocessor">#define MSIMU_GYRO_X_AXIS           MSIMU_REG_GYRO_X_AXIS</span>
<a name="l00081"></a><a class="code" href="group___m_s_i_m_u.html#ga4e8e8882a6b8639ea5687f5c965f0d0e">00081</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_GYRO_Y_AXIS           MSIMU_REG_GYRO_Y_AXIS</span>
<a name="l00082"></a><a class="code" href="group___m_s_i_m_u.html#ga3bf852de2191458bd76efa56a4b5590b">00082</a> <span class="preprocessor"></span><span class="preprocessor">#define MSIMU_GYRO_Z_AXIS           MSIMU_REG_GYRO_Z_AXIS</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>
<a name="l00084"></a><a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">00084</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>;    <span class="comment">/*!&lt; Array to hold I2C command data */</span>
<a name="l00085"></a><a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">00085</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>;      <span class="comment">/*!&lt; Array to hold I2C reply data */</span>
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga620eca05759c968f9ec07f43ac48b180">_MSIMUsendCMD</a>(tSensors link, ubyte cmd);
<a name="l00088"></a>00088 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga253f914b8feec4f753115641526ea23a">MSIMUreadTiltAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z);
<a name="l00089"></a>00089 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga8631f671fa303d83d25e7eb0c1b38fb5">MSIMUreadGyroAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z);
<a name="l00090"></a>00090 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#gad34ae53b61b5a0b5adc0a23e1e209acd">MSIMUreadAccelAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z);
<a name="l00091"></a>00091 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#gaf260cb22f3e20cba7616ef493686eeca">MSIMUreadMagneticFields</a>(tSensors link,  <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z);
<a name="l00092"></a>00092 <span class="keywordtype">int</span> <a class="code" href="group___m_s_i_m_u.html#gaa22086625869ed957b7f55415f6bd905">MSIMUreadHeading</a>(tSensors link);
<a name="l00093"></a>00093 <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga851b0927cb806cea01197fe59f5b7cc2">MSIMUsetGyroFilter</a>(tSensors link, ubyte level);
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 <span class="comment"></span>
<a name="l00096"></a>00096 <span class="comment">/**</span>
<a name="l00097"></a>00097 <span class="comment"> * Send a command to the sensor</span>
<a name="l00098"></a>00098 <span class="comment"> *</span>
<a name="l00099"></a>00099 <span class="comment"> * Note: this is an internal function and should be called directly</span>
<a name="l00100"></a>00100 <span class="comment"> * @param link the port number</span>
<a name="l00101"></a>00101 <span class="comment"> * @param cmd the command to be sent</span>
<a name="l00102"></a>00102 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00103"></a>00103 <span class="comment"> */</span>
<a name="l00104"></a><a class="code" href="group___m_s_i_m_u.html#ga620eca05759c968f9ec07f43ac48b180">00104</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga620eca05759c968f9ec07f43ac48b180">_MSIMUsendCMD</a>(tSensors link, ubyte cmd)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 3;                        <span class="comment">// Message size</span>
<a name="l00107"></a>00107   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00108"></a>00108         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#gaf0b1aebfb7bcbece8a48e41e22d381d4">MSIMU_REG_CMD</a>;  <span class="comment">// Register address</span>
<a name="l00109"></a>00109         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[3] = cmd;  <span class="comment">// command</span>
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>);
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 <span class="comment"></span>
<a name="l00115"></a>00115 <span class="comment">/**</span>
<a name="l00116"></a>00116 <span class="comment"> * Read all three tilt axes</span>
<a name="l00117"></a>00117 <span class="comment"> * @param link the port number</span>
<a name="l00118"></a>00118 <span class="comment"> * @param _x data for x axis in degrees per second</span>
<a name="l00119"></a>00119 <span class="comment"> * @param _y data for y axis in degrees per second</span>
<a name="l00120"></a>00120 <span class="comment"> * @param _z data for z axis in degrees per second</span>
<a name="l00121"></a>00121 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00122"></a>00122 <span class="comment"> */</span>
<a name="l00123"></a><a class="code" href="group___m_s_i_m_u.html#ga253f914b8feec4f753115641526ea23a">00123</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga253f914b8feec4f753115641526ea23a">MSIMUreadTiltAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z){
<a name="l00124"></a>00124         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00125"></a>00125   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00126"></a>00126         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#gad51c9b76f348df2462e82013ac22cb98">MSIMU_REG_TILT_ALL_AXES</a>;  <span class="comment">// Register address</span>
<a name="l00127"></a>00127 
<a name="l00128"></a>00128   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>, <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>, 3))
<a name="l00129"></a>00129     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00130"></a>00130 
<a name="l00131"></a>00131   _x = (<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] &gt;= 128) ? (<span class="keywordtype">int</span>)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] - 256 : (int)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0];
<a name="l00132"></a>00132   _y = (<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1] &gt;= 128) ? (<span class="keywordtype">int</span>)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1] - 256 : (int)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1];
<a name="l00133"></a>00133   _z = (<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2] &gt;= 128) ? (<span class="keywordtype">int</span>)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2] - 256 : (int)<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2];
<a name="l00134"></a>00134 
<a name="l00135"></a>00135   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00138"></a>00138 <span class="comment"></span>
<a name="l00139"></a>00139 <span class="comment">/**</span>
<a name="l00140"></a>00140 <span class="comment"> * Read all three axes of the gyro</span>
<a name="l00141"></a>00141 <span class="comment"> * @param link the port number</span>
<a name="l00142"></a>00142 <span class="comment"> * @param _x data for x axis in degrees per second</span>
<a name="l00143"></a>00143 <span class="comment"> * @param _y data for y axis in degrees per second</span>
<a name="l00144"></a>00144 <span class="comment"> * @param _z data for z axis in degrees per second</span>
<a name="l00145"></a>00145 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00146"></a>00146 <span class="comment"> */</span>
<a name="l00147"></a><a class="code" href="group___m_s_i_m_u.html#ga8631f671fa303d83d25e7eb0c1b38fb5">00147</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga8631f671fa303d83d25e7eb0c1b38fb5">MSIMUreadGyroAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z){
<a name="l00148"></a>00148         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00149"></a>00149   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00150"></a>00150         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#gae32355c9166051c7fd3a544c1718ada2">MSIMU_REG_GYRO_ALL_AXES</a>;  <span class="comment">// Register address</span>
<a name="l00151"></a>00151 
<a name="l00152"></a>00152   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>, <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>, 6))
<a name="l00153"></a>00153     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155   _x = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1]&lt;&lt;8));
<a name="l00156"></a>00156   _y = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[3]&lt;&lt;8));
<a name="l00157"></a>00157   _z = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[4] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[5]&lt;&lt;8));
<a name="l00158"></a>00158   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00159"></a>00159 }
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 <span class="comment"></span>
<a name="l00162"></a>00162 <span class="comment">/**</span>
<a name="l00163"></a>00163 <span class="comment"> * Read all of the accelerometer axes</span>
<a name="l00164"></a>00164 <span class="comment"> * @param link the port number</span>
<a name="l00165"></a>00165 <span class="comment"> * @param _x variable to hold X axis data</span>
<a name="l00166"></a>00166 <span class="comment"> * @param _y variable to hold Y axis data</span>
<a name="l00167"></a>00167 <span class="comment"> * @param _z variable to hold Z axis data</span>
<a name="l00168"></a>00168 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00169"></a>00169 <span class="comment"> */</span>
<a name="l00170"></a><a class="code" href="group___m_s_i_m_u.html#gad34ae53b61b5a0b5adc0a23e1e209acd">00170</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#gad34ae53b61b5a0b5adc0a23e1e209acd">MSIMUreadAccelAxes</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z){
<a name="l00171"></a>00171         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00172"></a>00172   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00173"></a>00173         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#ga15de9f02904e24957dea410855d5b5e4">MSIMU_REG_ACC_ALL_AXES</a>;  <span class="comment">// Register address</span>
<a name="l00174"></a>00174 
<a name="l00175"></a>00175   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>, <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>, 6))
<a name="l00176"></a>00176     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178   _x = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1]&lt;&lt;8));
<a name="l00179"></a>00179   _y = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[3]&lt;&lt;8));
<a name="l00180"></a>00180   _z = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[4] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[5]&lt;&lt;8));
<a name="l00181"></a>00181   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00184"></a>00184 
<a name="l00185"></a>00185 <span class="comment"></span>
<a name="l00186"></a>00186 <span class="comment">/**</span>
<a name="l00187"></a>00187 <span class="comment"> * Read all the magnetic field strengths</span>
<a name="l00188"></a>00188 <span class="comment"> * @param link the port number</span>
<a name="l00189"></a>00189 <span class="comment"> * @param _x variable to hold X axis data</span>
<a name="l00190"></a>00190 <span class="comment"> * @param _y variable to hold Y axis data</span>
<a name="l00191"></a>00191 <span class="comment"> * @param _z variable to hold Z axis data</span>
<a name="l00192"></a>00192 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00193"></a>00193 <span class="comment"> */</span>
<a name="l00194"></a><a class="code" href="group___m_s_i_m_u.html#gaf260cb22f3e20cba7616ef493686eeca">00194</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#gaf260cb22f3e20cba7616ef493686eeca">MSIMUreadMagneticFields</a>(tSensors link, <span class="keywordtype">int</span> &amp;_x, <span class="keywordtype">int</span> &amp;_y, <span class="keywordtype">int</span> &amp;_z){
<a name="l00195"></a>00195         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00196"></a>00196   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00197"></a>00197         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#ga15de9f02904e24957dea410855d5b5e4">MSIMU_REG_ACC_ALL_AXES</a>;  <span class="comment">// Register address</span>
<a name="l00198"></a>00198 
<a name="l00199"></a>00199   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>, <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>, 6))
<a name="l00200"></a>00200     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00201"></a>00201 
<a name="l00202"></a>00202   _x = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1]&lt;&lt;8));
<a name="l00203"></a>00203   _y = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[2] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[3]&lt;&lt;8));
<a name="l00204"></a>00204   _z = <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[4] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[5]&lt;&lt;8));
<a name="l00205"></a>00205 
<a name="l00206"></a>00206   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 <span class="comment"></span>
<a name="l00210"></a>00210 <span class="comment">/**</span>
<a name="l00211"></a>00211 <span class="comment"> * Read the current magnetic compass heading</span>
<a name="l00212"></a>00212 <span class="comment"> * @param link the port number</span>
<a name="l00213"></a>00213 <span class="comment"> * @return the current heading</span>
<a name="l00214"></a>00214 <span class="comment"> */</span>
<a name="l00215"></a><a class="code" href="group___m_s_i_m_u.html#gaa22086625869ed957b7f55415f6bd905">00215</a> <span class="keywordtype">int</span> <a class="code" href="group___m_s_i_m_u.html#gaa22086625869ed957b7f55415f6bd905">MSIMUreadHeading</a>(tSensors link)
<a name="l00216"></a>00216 {
<a name="l00217"></a>00217         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00218"></a>00218   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00219"></a>00219         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#gaa9876d9b5b9d3b7dfd15bc520fab614e">MSIMU_REG_COMPASS_HEADING</a>;  <span class="comment">// Register address</span>
<a name="l00220"></a>00220 
<a name="l00221"></a>00221   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>, <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>, 2))
<a name="l00222"></a>00222     <span class="keywordflow">return</span> 0;
<a name="l00223"></a>00223 
<a name="l00224"></a>00224   <span class="keywordflow">return</span> <a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[0] + ((int)(<a class="code" href="group___m_s_i_m_u.html#ga446be502f64e415ceaa9e0f335c6d459">MSIMU_I2CReply</a>[1]&lt;&lt;8));
<a name="l00225"></a>00225 }
<a name="l00226"></a>00226 
<a name="l00227"></a>00227 <span class="comment"></span>
<a name="l00228"></a>00228 <span class="comment">/**</span>
<a name="l00229"></a>00229 <span class="comment"> * Set the level of filtering of the Gryo readings.</span>
<a name="l00230"></a>00230 <span class="comment"> * @param link the port number</span>
<a name="l00231"></a>00231 <span class="comment"> * @param level the level of filtering (0-7) where 0 is none and 7 is the highest amount of filtering, 4 is the default level.</span>
<a name="l00232"></a>00232 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00233"></a>00233 <span class="comment"> */</span>
<a name="l00234"></a><a class="code" href="group___m_s_i_m_u.html#ga851b0927cb806cea01197fe59f5b7cc2">00234</a> <span class="keywordtype">bool</span> <a class="code" href="group___m_s_i_m_u.html#ga851b0927cb806cea01197fe59f5b7cc2">MSIMUsetGyroFilter</a>(tSensors link, ubyte level)
<a name="l00235"></a>00235 {
<a name="l00236"></a>00236         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[0] = 3;                        <span class="comment">// Message size</span>
<a name="l00237"></a>00237   <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[1] = <a class="code" href="group___m_s_i_m_u.html#gae90c6c346fd2ea07d29dd5312f69a38c">MSIMU_IMU_I2C_ADDR</a>;      <span class="comment">// I2C Address</span>
<a name="l00238"></a>00238         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[2] = <a class="code" href="group___m_s_i_m_u.html#ga4dd0432a1d355b19202419cd4fcf4d84">MSIMU_REG_GYRO_FILTER</a>;  <span class="comment">// Register address</span>
<a name="l00239"></a>00239         <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>[3] = level;  <span class="comment">// filtering level</span>
<a name="l00240"></a>00240 
<a name="l00241"></a>00241   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___m_s_i_m_u.html#gac2d44510ac67a1cf2c4657f1b726d79c">MSIMU_I2CRequest</a>);
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 <span class="preprocessor">#endif // __MSIMU_H__</span>
<a name="l00245"></a>00245 <span class="preprocessor"></span>
<a name="l00246"></a>00246 <span class="comment">/*</span>
<a name="l00247"></a>00247 <span class="comment"> * $Id: mindsensors-imu.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00248"></a>00248 <span class="comment"> */</span>
<a name="l00249"></a>00249 <span class="comment">/* @} */</span>
<a name="l00250"></a>00250 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:43 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
